package com.nd.service;

import com.nd.dao.AddressMapper;
import com.nd.dao.RegionMapper;
import com.nd.pojo.bean.*;
import com.nd.pojo.vo.wx.AddressDetailVo;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author : PengFei Zhang
 * @Data :2021/6/7  22:53
 * @Description :
 */
//收货地址  zpf
@Service
public class AdressServiceImpl implements AdressService {

    @Autowired
    AddressMapper addressMapper;
    @Autowired
    RegionMapper regionMapper;

    //详细信息
    @Override
    public AddressDetailVo addressDetail(Integer id) {
        //开始查询
        Address address = addressMapper.selectByPrimaryKey(id);
        AddressDetailVo addressDetailVo = new AddressDetailVo();
        addressDetailVo.setAddress(address.getAddress());
        addressDetailVo.setAreaId(address.getAreaId());
        //获得城市名称
       Integer cityId= address.getCityId();
        String cityName = regionMapper.selectByPrimaryKey(cityId).getName();
        addressDetailVo.setCityName(cityName);
        //获得地区名称
        String areaName = regionMapper.selectByPrimaryKey(address.getAreaId()).getName();
        addressDetailVo.setAreaName(areaName);
        addressDetailVo.setName(address.getName());
        addressDetailVo.setMobile(address.getMobile());
        addressDetailVo.setId(id);
        addressDetailVo.setCityId(cityId);
        Integer provinceId = address.getProvinceId();
        String provinceName = regionMapper.selectByPrimaryKey(provinceId).getName();
        addressDetailVo.setProvinceName(provinceName);
        addressDetailVo.setProvinceId(provinceId);
        return addressDetailVo;
    }
}
